﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestProject1.MainClasses;
namespace TestProject1
{
    [TestClass]
    public class TestUser
    {
        public IList<Departament> DepList = new List<Departament>();
        public IList<User> UserList = new List<User>();
        private IList<Role> URoleList = new List<Role>();
        [TestMethod]
        public void TestMethodUserInit()
        {   // Проверка инициализации пользователей
            User u = new User();
            Assert.AreEqual(0, u.GetID());
            Assert.AreEqual("", u.GetName());
            Assert.AreEqual("", u.GetLogin());
            Assert.AreEqual("", u.GetPass());
            Assert.AreEqual("", u.GetEmail());
            Assert.AreEqual('\0', u.GetSex());
            //Assert.IsNull(u.GetRole());
        }

        [TestMethod]
        public void TestMethodUserAdd()
        {   // Проверка добавления одного пользователя в список
            Departament dep = new Departament();
            DepList.Add(dep.add(22221, "name", "status"));
            ////////////////////////////
            User u = new User();
            Role r = new Role();
            URoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
            UserList.Add(u.add(1, "nik", "n1k1ta", "passwd", "aaa@mail.ru", 'm', r, dep));
            Assert.IsNotNull(UserList.First().GetID());
            //Assert.IsNotNull(t.GetUser());
            Assert.IsNotNull(UserList.First().GetName());
            Assert.IsNotNull(UserList.First().GetLogin());
            Assert.IsNotNull(UserList.First().GetPass());
            Assert.IsNotNull(UserList.First().GetEmail());
            Assert.IsNotNull(UserList.First().GetSex());
            Assert.IsNotNull(UserList.First());
        }

        [TestMethod]
        public void TestMethodUserEqualAdding()
        {
            // Проверка правильного заполнения полей при добавлении пользователя
            Departament dep = new Departament();
            DepList.Add(dep.add(22221, "name", "status"));
            ////////////////////////////
            User u = new User();
            int i = 1;
            string s1 = "nik";
            string s2 = "n1k1ta";
            string s3 = "passwd";
            string s4 = "aaa@mail.ru";
            char c = 'm';
            Role r = new Role();
            URoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
            UserList.Add(u.add(3, "vova", "n1k1ta", "qwerty", "his_mail@gmail.com", 'm', r, dep));
            Assert.AreNotEqual(i, UserList.First().GetID());
            Assert.AreNotEqual(s1, UserList.First().GetName());
            Assert.AreEqual(s2, UserList.First().GetLogin());
            Assert.AreNotEqual(s3, UserList.First().GetPass());
            Assert.AreNotEqual(s4, UserList.First().GetEmail());
            Assert.AreEqual(c, UserList.First().GetSex());
        }

        [TestMethod]
        public void TestMethodUserAddingToList()
        {   // Проверка добавления нескольких пользователей в список     
            for (int i = 0; i < 3; i++)
            {
                Departament dep = new Departament();
                DepList.Add(dep.add(22221, "name", "status"));
                ////////////////////////////
                User u = new User();
                Role r = new Role();
                URoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
                UserList.Add(u.add(i + 1, "vova", "n1k1ta", "qwerty", "his_mail@gmail.com", 'm', r, dep));
                Assert.IsNotNull(UserList.ElementAt(i));
            }
        }

        [TestMethod]
        public void TestMethodUserEdit()
        {   //Проверка изменения полей пользователя
            Departament dep = new Departament();
            DepList.Add(dep.add(22221, "name", "status"));
            ////////////////////////////
            User u = new User();
            Role r = new Role();
            URoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
            UserList.Add(u.add(1, "vova", "n1k1ta", "qwerty", "his_mail@gmail.com", 'm', r, dep));
            int i = 1;
            string s1 = "nik";
            string s2 = "n1k1ta";
            string s3 = "passwd";
            string s4 = "aaa@mail.ru";
            char c = 'm';
            UserList.First().edit(i, s1, s2, s3, s4, c, r, dep);
            //Assert.IsNotNull(UserList.First().GetID());
            Assert.AreEqual(i, UserList.First().GetID());
            //Assert.IsNotNull(UserList.First().GetName());
            Assert.AreEqual(s1, UserList.First().GetName());
            // Assert.IsNotNull(UserList.First().GetLogin());
            Assert.AreEqual(s2, UserList.First().GetLogin());
            // Assert.IsNotNull(UserList.First().GetPass());
            Assert.AreEqual(s3, UserList.First().GetPass());
            // Assert.IsNotNull(UserList.First().GetEmail());
            Assert.AreEqual(s4, UserList.First().GetEmail());
            // Assert.IsNotNull(UserList.First().GetSex());
            Assert.AreEqual(c, UserList.First().GetSex());
            // Assert.IsNotNull(UserList.First());
        }

        [TestMethod]
        public void TestMethodUserRemove()
        {   //Проверка удаления пользователя из списка с именем "nikita"
            Departament dep = new Departament();
            DepList.Add(dep.add(22221, "name", "status"));
            ////////////////////////////
            User u = new User();
            Role r = new Role();
            URoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
            UserList.Add(u.add(1, "vova", "ukrvovan", "qwerty", "vova_mail@gmail.com", 'm', r, dep));
            User u1 = new User();
            UserList.Add(u1.add(1, "nikita", "n1k1ta", "n1k1tkaaa", "nikita_mail@gmail.com", 'm', r, dep));
            User u2 = new User();
            UserList.Add(u2.add(1, "anya", "anna21", "1qwerty1", "anya_mail@gmail.com", 'f', r, dep));
            User u3 = new User();
            UserList.Add(u3.add(1, "tanya", "tanya21", "2qwerty2", "tanya_mail@gmail.com", 'f', r, dep));
            int cnt = UserList.Count();
            for (int i = 0; i < UserList.Count(); i++)
            {
                if (UserList.ElementAt(i).GetName() == "nikita")
                {
                    UserList.RemoveAt(i); cnt--;
                    Assert.IsNotNull(UserList.ElementAt(i + 1));
                }
                Assert.AreEqual(cnt, UserList.Count());
            }
            for (int j = 0; j < UserList.Count(); j++)
            {
                Assert.AreNotEqual("nikita", UserList.ElementAt(j));
            }
        }
    }
}